package com.community.common.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.community.common.pojo.Constant;
import com.community.common.pojo.domain.UserPermission;
import com.community.common.mapper.UserPermissionMapper;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户相机权限表 服务实现类
 * </p>
 *
 * @author superman
 * @since 2020-08-02
 */
@Service
public class UserPermissionService extends ServiceImpl<UserPermissionMapper, UserPermission> {

    public int getPermission(UserPermission userPermission) {
        //0-未知 1-不允许 2-允许 3-失败
        int permission = 0;
        if (userPermission != null) {
            Integer currentAllow = userPermission.getCurrentAllow();
            Integer targetAllow = userPermission.getTargetAllow();
            Integer commandStatus = userPermission.getCommandStatus();
            if (commandStatus.equals(Constant.COMMAND_FAIL)) {
                permission = 3;
            } else if (currentAllow == 0 && targetAllow == 0) {
                permission = 1;
            } else if (currentAllow == 1 && targetAllow == 1) {
                permission = 2;
            }
        }
        return permission;
    }
}
